package com.example.lovedogs.gouquan;


import com.example.lovedogs.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

public class Mengyoulijian extends Activity implements OnTouchListener{
	private ScrollView scrollView;
    private LinearLayout bottomLinearLayout;
    private int scrollY;
    ListView lv;
    Intent intent ;
	ImageView flagImage;
	String[] names = new String[] { "bolivia", "brazil", "canada", "china",
			"japan" };
	int[] namesId = new int[] { R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_doghouse);
		
//		scrollView = (ScrollView)findViewById(R.id.scrollView1);
//		scrollView.setOnTouchListener(this);
//		bottomLinearLayout = (LinearLayout)findViewById(R.id.bottomLinearlayout);
//		bottomLinearLayout.getBackground().setAlpha(0);  
		
		lv = (ListView) findViewById(R.id.listView1);
		lv.setAdapter(new MyAdapter());
	}



	@Override
	public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE:
             scrollY=v.getScrollY();
             if(scrollY<=255&&scrollY>=0){
            	  bottomLinearLayout.getBackground().setAlpha(scrollY);
             }
             else {
            	 bottomLinearLayout.getBackground().setAlpha(255);
			}
            break;
        case MotionEvent.ACTION_UP:
        	if(scrollY<=255&&scrollY>=0){
          	  bottomLinearLayout.getBackground().setAlpha(scrollY);
           }
           else {
          	 bottomLinearLayout.getBackground().setAlpha(255);
			}
        	 break;
        default:
            break;
        }
        return false;
    }
	
	class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return names.length;
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(final int position, View view, ViewGroup group) {
			LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(
					R.layout.item, null);
			flagImage = (ImageView) layout.findViewById(R.id.item_img);
//			flagImage.getDrawable(namesId[position]);
			flagImage.setImageResource(namesId[position]);
			final Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
					namesId[position]);
			flagImage.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					intent = getIntent();
					intent.putExtra("bitmap", bitmap);
					intent.setClass(Mengyoulijian.this, MengyoulijianToShow.class);
					startActivity(intent);
				}
			});
			TextView flagName = (TextView) layout.findViewById(R.id.item_tv);
			flagName.setText(names[position]);
			return layout;
		}
		
	}
}

